//
//  SyncCPU_and_GPU.m
//  Metal-Master
//
//  Created by 杨冰冰 on 2020/6/18.
//  Copyright © 2020 杨冰冰. All rights reserved.
//

#import "SyncCPU_and_GPU.h"
#import "CPUAndGPUSyncRenderer.h"

@implementation SyncCPU_and_GPU
{
    MTKView *_view;

    CPUAndGPUSyncRenderer *_renderer;
}
- (void)viewDidLoad {
    // Set the view to use the default device.
    _view = [[MTKView alloc] initWithFrame:self.bounds] ;
    
    [self addSubview:_view];
    
    _view.device = MTLCreateSystemDefaultDevice();

    if(!_view.device)
    {
        NSLog(@"Metal is not supported on this device");
        return;
    }

    _renderer = [[CPUAndGPUSyncRenderer alloc] initWithMetalKitView:_view];

    if(!_renderer)
    {
        NSLog(@"Renderer failed initialization");
        return;
    }

    // Initialize the renderer with the view size.
    [_renderer mtkView:_view drawableSizeWillChange:_view.drawableSize];

    _view.delegate = _renderer;
}


@end
